﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ProjectSemIII.Entity;

namespace ProjectSemIII.Process
{
    public class Statistics
    {
        private project_sem3Entities projectEntity;
        public Statistics()
        {
            projectEntity = new project_sem3Entities();
        }
        public int getTotalSurvey()
        {
            List<Survey> lsv = new List<Survey>();
            try
            {
                lsv = (from s in projectEntity.Surveys
                       select s).ToList();
                return lsv.Count;
            }
            catch
            {
                return 0;
            }
        }
        public int getSurveyByStatus(int status)
        {
            List<Survey> lsv = new List<Survey>();
            try
            {
                lsv = (from s in projectEntity.Surveys
                       where s.SurveyStatus == status
                       select s).ToList();
                return lsv.Count;
            }
            catch
            {
                return 0;
            }
        }

        public int getSurveysByGroup(int groupUser)
        {
            List<Survey> lsv = new List<Survey>();
            try
            {
                lsv = (from s in projectEntity.Surveys
                       where s.SurveyPlayer == groupUser
                       select s).ToList();
                return lsv.Count;
            }
            catch
            {
                return 0;
            }
        }
        public int gettotalUser()
        {
            List<User> lu = new List<User>();
            try
            {
                lu = (from u in projectEntity.Users
                      select u).ToList();
                return lu.Count;
            }
            catch
            {
                return 0;
            }
        }
        public int getTotalWiner()
        {
            List<Winer> lw = new List<Winer>();
            try
            {
                lw = (from u in projectEntity.Winers
                      select u).ToList();
                return lw.Count;
            }
            catch
            {
                return 0;
            }
        }

        public List<Winer> getListNewWinner()
        {
            List<Winer> lw = new List<Winer>();
            try
            {
                lw = (from w in projectEntity.Winers
                      orderby w.SurveyID descending
                      select w).Take(3).ToList();
                return lw;
            }
            catch
            {
                return lw;
            }
        }
    }
}